package cn.wk.dao.impl;

import cn.wk.dao.ClassDao;
import cn.wk.dao.TeacherDao;
import cn.wk.entity.Classes;
import cn.wk.entity.Teacher;
import cn.wk.util.JDBCUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class ClassesDaolmpl implements ClassDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtil.getDataSource());
    @Override
    public List<Classes> getAllClasses(Object...obj) {
        String sql="select * from classes limit ?,?";
        List<Classes> list=  template.query(sql, new BeanPropertyRowMapper<>(Classes.class),obj);
        return list;
    }
    @Override
    public int  CountSize(){
        String sql="select count(*) from classes";
        int b=template.queryForObject(sql,Integer.class);
        return b;
    }

    @Override
    public List<Classes> getByClassessNameandId() {
        String sql="select cid,cname from classes";
        List<Classes> list=  template.query(sql, new BeanPropertyRowMapper<>(Classes.class));
        return list;
    }

    @Override
    public int AddAllClasses(String sql){
        int b=template.update(sql);
        return b;
    }

    @Override
    public int AddClasses(Object... obj) {
        String sql="insert classes values(null,?)";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int MidffClasses(Object... obj) {
        String sql="update classes set cname=? where cid=?";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int DelClasses(Object... obj) {
       return 0;
    }



    @Override
    public Classes findClassesById(int tid) {
        String sql="select * from classes where cid=?";
      Classes classes=  template.queryForObject(sql,new BeanPropertyRowMapper<>(Classes.class),tid);
        return classes;
    }


}
